
#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QComboBox>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QGroupBox>
#include <QGridLayout>
#include <QGroupBox>
#include <QTextEdit>
#include <QHBoxLayout>
#include <QVBoxLayout>

// ---
#include <YouwantWidget>
#include <QApplication>
#include <QClipboard>

#include <QTabWidget>
#include <BaseWidget>
#include <QListWidget>

#include <QResizeEvent>
#include <QTimer>

MainWindow::MainWindow(QWidget *parent) : QWidget(parent)
, ui(new Ui::MainWindow)
, resizeing(false)
, timer(new QTimer(this))
{

    ui->setupUi(this);

    QTabWidget *widget = ui->widget;
    widget->clear();
    widget->addTab(new YouwantWidget, "模板创作");

    connect(widget, &QTabWidget::tabBarClicked, [=](int index){
        BaseWidget *base = (BaseWidget*)widget->widget(index);
        resizeing = true;
        resize(base->widgetSize());
        timer->start();
    });

    connect(this, &MainWindow::changeSize, [=](QSize size){
        if (resizeing == true) return;
        ((BaseWidget*)widget->currentWidget())->setWidgetSize(size);
    });

    timer->setInterval(500);
    connect(timer, &QTimer::timeout, [=](){
        resizeing = false;
    });
}
MainWindow::~MainWindow()
{
	
}

void MainWindow::resizeEvent(QResizeEvent *event) {
    emit changeSize(event->size());
}
